home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectMusic / AudioFX / audiofx.cpp next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  57.9 KB  |  1,455 lines

  1. //-----------------------------------------------------------------------------
  2. // File: AudioFX.cpp
  3. //
  4. // Desc: Sample to demonstrate soundFX and parameters with DirectMusic
  5. //
  6. //
  7. // Copyright ( c ) 1998-2001 Microsoft Corporation. All rights reserved.
  8. //-----------------------------------------------------------------------------
  9. #define STRICT
  10. #include <windows.h>
  11. #include <basetsd.h>
  12. #include <mmsystem.h>
  13. #include <mmreg.h>
  14. #include <dxerr8.h>
  15. #include <dsound.h>
  16. #include <cguid.h>
  17. #include <commctrl.h>
  18. #include <commdlg.h>
  19. #include <dsound.h>
  20. #include <stdio.h>
  21. #include <tchar.h>
  22.  
  23. #include "DMUtil.h"
  24. #include "DSUtil.h"
  25. #include "DXUtil.h"
  26. #include "resource.h"
  27.  
  28.  
  29.  
  30.  
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Function-prototypes
  34. //-----------------------------------------------------------------------------
  35. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg,  WPARAM wParam, LPARAM lParam );
  36. VOID    OnInitDialog( HWND hDlg );
  37. VOID    OnOpenSoundFile( HWND hDlg );
  38. HRESULT OnPlaySound( HWND hDlg );
  39. VOID    OnEffectChanged( HWND hDlg );
  40. HRESULT ValidateFile( HWND hDlg, TCHAR* strFileName );
  41. HRESULT CreateAndFillBuffer( HWND hDlg, DWORD dwCreationFlags );
  42. VOID    SetBufferOptions( LONG lFrequency, LONG lPakn, LONG lVolume );
  43. VOID    EnablePlayUI( HWND hDlg, BOOL bEnable );
  44. HRESULT ProcessDirectMusicMessages( HWND hDlg );
  45. VOID    LoadParameterUI ( HWND hDlg, DWORD dwFXType );
  46. VOID    ResetParameterUI ( HWND hDlg );
  47.  
  48.  
  49.  
  50.  
  51. //-----------------------------------------------------------------------------
  52. // Name: enum ESFXType
  53. // Desc: each is a unique identifier mapped to a DirectSoundFX
  54. //-----------------------------------------------------------------------------
  55. enum ESFXType
  56. {
  57.     eSFX_chorus = 0,
  58.     eSFX_compressor,
  59.     eSFX_distortion,
  60.     eSFX_echo,
  61.     eSFX_flanger,
  62.     eSFX_gargle,
  63.     eSFX_parameq,
  64.     eSFX_reverb,
  65.  
  66.     // number of enumerated effects
  67.     eNUM_SFX
  68. };
  69.  
  70.  
  71.  
  72.  
  73. //-----------------------------------------------------------------------------
  74. // Name: class CSoundFXManager
  75. // Desc: Takes care of effects for one DirectSoundBuffer
  76. //-----------------------------------------------------------------------------
  77. class CSoundFXManager
  78. {
  79. public:
  80.     CSoundFXManager();
  81.     ~CSoundFXManager();
  82.  
  83. public: // interface
  84.     HRESULT Initialize ( IDirectMusicAudioPath8 * pAudioPath8, BOOL bLoadDefaultParamValues );
  85.     HRESULT UnInitialize ();
  86.  
  87.     HRESULT SetFXEnable( DWORD esfxType );
  88.     HRESULT ActivateFX();
  89.     HRESULT DisableAllFX();
  90.     HRESULT LoadCurrentFXParameters();
  91.  
  92. public: // members
  93.     LPDIRECTSOUNDFXCHORUS8      m_lpChorus;
  94.     LPDIRECTSOUNDFXCOMPRESSOR8  m_lpCompressor;
  95.     LPDIRECTSOUNDFXDISTORTION8  m_lpDistortion;
  96.     LPDIRECTSOUNDFXECHO8        m_lpEcho;
  97.     LPDIRECTSOUNDFXFLANGER8     m_lpFlanger;
  98.     LPDIRECTSOUNDFXGARGLE8      m_lpGargle;
  99.     LPDIRECTSOUNDFXPARAMEQ8     m_lpParamEq;
  100.     LPDIRECTSOUNDFXWAVESREVERB8 m_lpReverb;
  101.  
  102.     DSFXChorus                  m_paramsChorus;
  103.     DSFXCompressor              m_paramsCompressor;
  104.     DSFXDistortion              m_paramsDistortion;
  105.     DSFXEcho                    m_paramsEcho;
  106.     DSFXFlanger                 m_paramsFlanger;
  107.     DSFXGargle                  m_paramsGargle;
  108.     DSFXParamEq                 m_paramsParamEq;
  109.     DSFXWavesReverb             m_paramsReverb;
  110.  
  111.     LPDIRECTSOUNDBUFFER8        m_lpDSB8;
  112.     IDirectMusicAudioPath8 *    m_pAudioPath;
  113.  
  114. protected:
  115.     DSEFFECTDESC                m_rgFxDesc[eNUM_SFX];
  116.     const GUID *                m_rgRefGuids[eNUM_SFX];
  117.     LPVOID *                    m_rgPtrs[eNUM_SFX];
  118.     BOOL                        m_rgLoaded[eNUM_SFX];
  119.     DWORD                       m_dwNumFX;
  120.  
  121.     HRESULT EnableGenericFX( GUID guidSFXClass, REFGUID rguidInterface, LPVOID * ppObj );
  122.     HRESULT LoadDefaultParamValues();
  123. };
  124.  
  125.  
  126.  
  127.  
  128. //-----------------------------------------------------------------------------
  129. // defines and global variables
  130. //-----------------------------------------------------------------------------
  131. #define             DEFAULT_SLIDER_MIN          1
  132. #define             DEFAULT_SLIDER_MAX          0x7FFFFF
  133. #define             DEFAULT_SLIDER_INC          DEFAULT_SLIDER_MAX >> 11
  134.  
  135. CMusicManager *     g_lpMusicManager        = NULL;
  136. CMusicSegment *     g_pSegment              = NULL;
  137. CSoundFXManager *   g_lpFXManager           = NULL;
  138. HINSTANCE           g_hInst                 = NULL;
  139. TCHAR               g_strFileName[MAX_PATH];
  140. DWORD               g_dwCurrentFXType       = eSFX_chorus;
  141. HANDLE              g_hDMusicMessageEvent   = NULL;
  142.  
  143. const TCHAR *       g_strFXNames[] = { "Chorus", "Compressor", "Distortion", "Echo", 
  144.                                        "Flanger", "Gargle", "Param Eq", "Reverb" };
  145.  
  146.  
  147.  
  148.  
  149. //-----------------------------------------------------------------------------
  150. // Name: WinMain()
  151. // Desc: Entry point for the application.  Since we use a simple dialog for 
  152. //       user interaction we don't need to pump messages.
  153. //-----------------------------------------------------------------------------
  154. INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, INT nCmdShow )
  155. {
  156.     HWND    hDlg = NULL;
  157.     BOOL    bDone = FALSE;
  158.     int     nExitCode;
  159.     HRESULT hr; 
  160.     DWORD   dwResult;
  161.     MSG     msg;
  162.  
  163.     g_hInst = hInst;
  164.  
  165.     CoInitialize( NULL );
  166.  
  167.     // Init the common control dll 
  168.     InitCommonControls();
  169.  
  170.     // Display the main dialog box.
  171.     hDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc );
  172.     ShowWindow( hDlg, nCmdShow );
  173.     UpdateWindow( hDlg );
  174.  
  175.     while( !bDone ) 
  176.     { 
  177.         dwResult = MsgWaitForMultipleObjects( 1, &g_hDMusicMessageEvent, 
  178.                                               FALSE, INFINITE, QS_ALLEVENTS );
  179.         switch( dwResult )
  180.         {
  181.             case WAIT_OBJECT_0 + 0:
  182.                 // g_hDPMessageEvent is signaled, so there are
  183.                 // DirectPlay messages available
  184.                 if( FAILED( hr = ProcessDirectMusicMessages( hDlg ) ) ) 
  185.                 {
  186.                     DXTRACE_ERR( TEXT("ProcessDirectMusicMessages"), hr );
  187.                     return FALSE;
  188.                 }
  189.                 break;
  190.  
  191.             case WAIT_OBJECT_0 + 1:
  192.                 // Windows messages are available
  193.                 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
  194.                 { 
  195.                     if( !IsDialogMessage( hDlg, &msg ) )  
  196.                     {
  197.                         TranslateMessage( &msg ); 
  198.                         DispatchMessage( &msg ); 
  199.                     }
  200.  
  201.                     if( msg.message == WM_QUIT )
  202.                     {
  203.                         nExitCode = (int)msg.wParam;
  204.                         bDone     = TRUE;
  205.                         DestroyWindow( hDlg );
  206.                     }
  207.                 }
  208.                 break;
  209.         }
  210.     }
  211.  
  212.     CoUninitialize();
  213.  
  214.     return nExitCode;
  215. }
  216.  
  217.  
  218.  
  219.  
  220. //-----------------------------------------------------------------------------
  221. // Name: MainDlgProc()
  222. // Desc: Handles dialog messages
  223. //-----------------------------------------------------------------------------
  224. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  225. {
  226.     HRESULT hr;
  227.  
  228.     switch( msg ) 
  229.     {
  230.         case WM_COMMAND:
  231.             switch( LOWORD(wParam) )
  232.             {
  233.                 case IDOK:
  234.                 case IDCANCEL:
  235.                     PostQuitMessage( 0 );
  236.                     break;
  237.  
  238.                 case IDC_BUTTON_OPEN:
  239.                     OnOpenSoundFile( hDlg );
  240.                     break;
  241.  
  242.                 case IDC_BUTTON_PLAY:
  243.                     if( FAILED( hr = OnPlaySound( hDlg ) ) )
  244.                     {
  245.                         DXTRACE_ERR( TEXT("OnPlaySound"), hr );
  246.                         MessageBox( hDlg, "Error playing DirectSound buffer."
  247.                                     "Sample will now exit.", "DirectSound Sample", 
  248.                                     MB_OK | MB_ICONERROR );
  249.                         EndDialog( hDlg, IDABORT );
  250.                     }
  251.                     break;
  252.  
  253.                 case IDC_BUTTON_STOP:
  254.                     if( g_pSegment )
  255.                         g_pSegment->Stop();
  256.                     EnablePlayUI( hDlg, TRUE );
  257.                     SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("Sound stopped.") );
  258.                     break;
  259.  
  260.                 case IDC_RADIO_TRIANGLE:
  261.                 case IDC_RADIO_SQUARE:
  262.                 case IDC_RADIO_SINE:
  263.                 case IDC_RADIO_NEG_180:
  264.                 case IDC_RADIO_NEG_90:
  265.                 case IDC_RADIO_ZERO:
  266.                 case IDC_RADIO_90:
  267.                 case IDC_RADIO_180:
  268.                     OnEffectChanged( hDlg );
  269.                     break;
  270.  
  271.                 default:
  272.                     if( LOWORD( wParam ) >= IDC_RADIO_CHORUS &&
  273.                         LOWORD( wParam ) <= IDC_RADIO_REVERB )
  274.                     {
  275.                         g_dwCurrentFXType = LOWORD( wParam ) - IDC_RADIO_CHORUS;
  276.                         LoadParameterUI( hDlg, g_dwCurrentFXType );
  277.                     }
  278.                     else
  279.                         return FALSE; // Didn't handle message
  280.             }
  281.             break;
  282.  
  283.         case WM_INITDIALOG:
  284.             OnInitDialog( hDlg );
  285.             break;
  286.  
  287.         case WM_NOTIFY:
  288.         {
  289.             //LPNMHDR pnmh = ( LPNMHDR ) lParam;
  290.             //if( pnmh->code >= IDC_SLIDER1 && pnmh->code <= IDC_SLIDER6 )
  291.             //{
  292.                 OnEffectChanged( hDlg );
  293.             //}
  294.             break;
  295.         }
  296.         case WM_DESTROY:
  297.             // Cleanup everything
  298.             CloseHandle( g_hDMusicMessageEvent );
  299.             SAFE_DELETE( g_lpFXManager );
  300.             SAFE_DELETE( g_pSegment );
  301.             SAFE_DELETE( g_lpMusicManager );
  302.             break; 
  303.  
  304.         default:
  305.             return FALSE; // Didn't handle message
  306.     }
  307.  
  308.     return TRUE; // Handled message
  309. }
  310.  
  311.  
  312.  
  313.  
  314. //-----------------------------------------------------------------------------
  315. // Name: OnInitDialog()
  316. // Desc: Initializes the dialogs (sets up UI controls, etc.)
  317. //-----------------------------------------------------------------------------
  318. VOID OnInitDialog( HWND hDlg )
  319. {
  320.     HRESULT hr;
  321.  
  322.     HICON hIcon = LoadIcon( g_hInst, MAKEINTRESOURCE( IDI_ICON ) );
  323.     SendMessage( hDlg, WM_SETICON, ICON_BIG, ( LPARAM ) hIcon );
  324.     SendMessage( hDlg, WM_SETICON, ICON_SMALL, ( LPARAM ) hIcon );
  325.     
  326.     // create a DirectMusicManager
  327.     g_lpMusicManager = new CMusicManager();
  328.     g_lpFXManager = new CSoundFXManager();
  329.  
  330.     // create a music manager with 128 performance channels, stereo (not shared)
  331.     if( FAILED( hr = g_lpMusicManager->Initialize( hDlg, 128, DMUS_APATH_DYNAMIC_STEREO ) ) )
  332.     {
  333.         DXTRACE_ERR( TEXT("Initialize"), hr );
  334.         MessageBox( hDlg, "Error initializing DirectSound.  Sample will now exit.", 
  335.                     "DirectSound Sample", MB_OK | MB_ICONERROR );
  336.         PostQuitMessage( 0 );
  337.         return;
  338.     }
  339.  
  340.     // Register segment notification, to know when segment stopped
  341.     g_hDMusicMessageEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
  342.     GUID guid = GUID_NOTIFICATION_SEGMENT;
  343.  
  344.     IDirectMusicPerformance * pPerf = g_lpMusicManager->GetPerformance();
  345.     pPerf->AddNotificationType( guid );
  346.     pPerf->SetNotificationHandle( g_hDMusicMessageEvent, 0 );  
  347.  
  348.     // Load default file
  349.     TCHAR strFile[MAX_PATH];
  350.     GetWindowsDirectory( strFile, MAX_PATH );
  351.     lstrcat( strFile, "\\media\\ding.wav" );
  352.     
  353.     if( FAILED( hr = ValidateFile( hDlg, strFile ) ) )
  354.     {
  355.         // Set the UI controls
  356.         SetDlgItemText( hDlg, IDC_TEXT_FILENAME, TEXT("") );
  357.         SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("No file loaded.") );
  358.         EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_PLAY ), FALSE );
  359.         EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_STOP ), FALSE );
  360.         return;
  361.     }
  362.  
  363.     if( SUCCEEDED( hr = g_lpMusicManager->CreateSegmentFromFile( &g_pSegment, g_strFileName, TRUE, FALSE ) ) )
  364.     {
  365.         g_lpFXManager->Initialize( g_lpMusicManager->GetDefaultAudioPath(), TRUE );
  366.  
  367.         // reset the manager so nothing is enabled - the parameters retained, however
  368.         g_lpFXManager->UnInitialize();
  369.  
  370.         SAFE_DELETE( g_pSegment );
  371.     }
  372.  
  373.     // set UI defaults
  374.     CheckDlgButton( hDlg, IDC_CHECK_LOOP, BST_CHECKED );
  375.     CheckRadioButton( hDlg, IDC_RADIO_CHORUS, IDC_RADIO_REVERB, IDC_RADIO_CHORUS );
  376.     LoadParameterUI( hDlg, g_dwCurrentFXType );
  377.     EnablePlayUI( hDlg, TRUE );
  378. }
  379.  
  380.  
  381.  
  382.  
  383. //-----------------------------------------------------------------------------
  384. // Name: OnPlaySound()
  385. // Desc: User hit the "Play" button
  386. //-----------------------------------------------------------------------------
  387. HRESULT OnPlaySound( HWND hDlg )
  388. {
  389.     HRESULT hr;
  390.     DWORD   i;
  391.  
  392.     BOOL bLooped = ( IsDlgButtonChecked( hDlg, IDC_CHECK_LOOP ) == BST_CHECKED );
  393.  
  394.     // Free any previous sound and FXs
  395.     g_lpFXManager->DisableAllFX();
  396.  
  397.     SAFE_DELETE( g_pSegment );
  398.     g_lpMusicManager->CollectGarbage();
  399.  
  400.     // For DirectMusic must know if the file is a standard MIDI file or not
  401.     // in order to load the correct instruments.
  402.     BOOL bMidiFile = FALSE;
  403.     if( strstr( g_strFileName, ".mid" ) != NULL ||
  404.         strstr( g_strFileName, ".rmi" ) != NULL ) 
  405.     {
  406.         bMidiFile = TRUE;
  407.     }
  408.  
  409.     // Since the user can change the focus before the sound is played, 
  410.     // we need to create the sound buffer every time the play button is pressed 
  411.     // Load the segment file into a DirectMusicSegment buffer
  412.     if( FAILED( hr = g_lpMusicManager->CreateSegmentFromFile( &g_pSegment, g_strFileName, 
  413.                                                               TRUE, bMidiFile ) ) )
  414.     {
  415.         // Not a critical failure, so just update the status
  416.         DXTRACE_ERR_NOMSGBOX( TEXT("Create"), hr );
  417.         SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("Could not load the segment file.") );
  418.         return S_FALSE; 
  419.     }
  420.  
  421.     g_lpFXManager->Initialize( g_lpMusicManager->GetDefaultAudioPath(), FALSE );
  422.     for( i = IDC_CHECK_CHORUS; i <= IDC_CHECK_REVERB; i++ )
  423.     {
  424.         if( IsDlgButtonChecked( hDlg, i ) == BST_CHECKED )
  425.             g_lpFXManager->SetFXEnable( i - IDC_CHECK_CHORUS );
  426.     }
  427.     g_lpFXManager->ActivateFX();
  428.     g_lpFXManager->LoadCurrentFXParameters();
  429.  
  430.     // Play the sound
  431.     if( FAILED( hr = g_pSegment->SetRepeats( ( bLooped ?  DMUS_SEG_REPEAT_INFINITE : 0 ) ) ) )
  432.         return DXTRACE_ERR( TEXT("SetRepeats"), hr );
  433.     if( FAILED( hr = g_pSegment->Play( 0 ) ) )
  434.         return DXTRACE_ERR( TEXT("Play"), hr );
  435.  
  436.     // Update the UI controls to show the sound as playing
  437.     EnablePlayUI( hDlg, FALSE );
  438.     SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("Sound playing.") );
  439.  
  440.     return S_OK;
  441. }
  442.  
  443.  
  444.  
  445.  
  446. //-----------------------------------------------------------------------------
  447. // Name: OnOpenSoundFile()
  448. // Desc: Called when the user requests to open a sound file
  449. //-----------------------------------------------------------------------------
  450. VOID OnOpenSoundFile( HWND hDlg ) 
  451. {
  452.     static TCHAR strFileName[MAX_PATH] = TEXT("");
  453.     static TCHAR strPath[MAX_PATH] = TEXT("");
  454.  
  455.     // Setup the OPENFILENAME structure
  456.     OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL,
  457.                          TEXT("Audio Files\0*.sgt;*.mid;*.rmi;*.wav\0All Files\0*.*\0\0"), NULL,
  458.                          0, 1, strFileName, MAX_PATH, NULL, 0, strPath,
  459.                          TEXT("Open Audio File"),
  460.                          OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0,
  461.                          TEXT(".wav"), 0, NULL, NULL };
  462.  
  463.     // Get the default media path (something like C:\WINDOWS\MEDIA)
  464.     if( '\0' == strPath[0] )
  465.     {
  466.         GetWindowsDirectory( strPath, MAX_PATH );
  467.         if( strcmp( &strPath[strlen(strPath)], TEXT("\\") ) )
  468.             strcat( strPath, TEXT("\\") );
  469.         strcat( strPath, TEXT("MEDIA") );
  470.     }
  471.  
  472.     // Update the UI controls to show the sound as loading a file
  473.     EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_PLAY ), FALSE );
  474.     EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_STOP ), FALSE );
  475.     SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("Loading file...") );
  476.  
  477.     if( g_pSegment )
  478.         g_pSegment->Stop();
  479.  
  480.     // Display the OpenFileName dialog. Then, try to load the specified file
  481.     if( TRUE != GetOpenFileName( &ofn ) )
  482.     {
  483.         if( g_pSegment )
  484.         {
  485.             EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_PLAY ), TRUE );
  486.             EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_STOP ), TRUE );
  487.         }
  488.  
  489.         SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("Load aborted.") );
  490.         return;
  491.     }
  492.  
  493.     SetDlgItemText( hDlg, IDC_TEXT_FILENAME, TEXT("") );
  494.  
  495.     // Make sure file is a valid file
  496.     ValidateFile( hDlg, strFileName );
  497.  
  498.     EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_PLAY ), TRUE );
  499.     EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_STOP ), FALSE );
  500.  
  501.     // Remember the path for next time
  502.     strcpy( strPath, strFileName );
  503.     char* strLastSlash = strrchr( strPath, '\\' );
  504.     strLastSlash[0] = '\0';
  505. }
  506.  
  507.  
  508.  
  509.  
  510. //-----------------------------------------------------------------------------
  511. // Name: EnablePlayUI()
  512. // Desc: Enables or disables the Play UI controls 
  513. //-----------------------------------------------------------------------------
  514. VOID EnablePlayUI( HWND hDlg, BOOL bEnable )
  515. {
  516.     if( bEnable )
  517.     {
  518.         EnableWindow( GetDlgItem( hDlg, IDC_CHECK_LOOP      ), TRUE );
  519.         EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_PLAY     ), TRUE );
  520.         EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_STOP     ), FALSE );
  521.         SetFocus(     GetDlgItem( hDlg, IDC_BUTTON_PLAY )   );
  522.     }
  523.     else
  524.     {
  525.         EnableWindow( GetDlgItem( hDlg, IDC_CHECK_LOOP      ), FALSE );
  526.         EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_PLAY     ), FALSE );
  527.         EnableWindow( GetDlgItem( hDlg, IDC_BUTTON_STOP     ), TRUE );
  528.         SetFocus(     GetDlgItem( hDlg, IDC_BUTTON_STOP )   );
  529.     }
  530.  
  531.     for( DWORD i = IDC_CHECK_CHORUS; i <= IDC_CHECK_REVERB; i++ )
  532.         EnableWindow( GetDlgItem( hDlg, i ), bEnable );
  533. }
  534.  
  535.  
  536.  
  537.  
  538. //-----------------------------------------------------------------------------
  539. // Name: ResetParameterUI()
  540. // Desc: Blanks the paramter UI
  541. //-----------------------------------------------------------------------------
  542. VOID ResetParameterUI( HWND hwndDlg )
  543. {
  544.     HWND hwndItem;
  545.     DWORD i;
  546.  
  547.     for ( i = IDC_PARAM_NAME1; i <= IDC_PARAM_MAX6; i++ )
  548.     {
  549.         hwndItem = GetDlgItem( hwndDlg, i );
  550.         SendMessage( hwndItem, WM_SETTEXT, 0, ( LPARAM ) TEXT( "- - -" ) );
  551.         EnableWindow( hwndItem, FALSE );
  552.     }
  553.  
  554.     for ( i = IDC_SLIDER1; i <= IDC_SLIDER6; i += 5 )
  555.     {
  556.         PostMessage( GetDlgItem( hwndDlg, i ), TBM_SETRANGEMIN, FALSE, DEFAULT_SLIDER_MIN );
  557.         PostMessage( GetDlgItem( hwndDlg, i ), TBM_SETRANGEMAX, FALSE, DEFAULT_SLIDER_MAX );
  558.         PostMessage( GetDlgItem( hwndDlg, i ), TBM_SETLINESIZE, FALSE, DEFAULT_SLIDER_INC );
  559.         PostMessage( GetDlgItem( hwndDlg, i ), TBM_SETPOS, TRUE, 0 );
  560.     }
  561.  
  562.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_TRIANGLE ), FALSE );
  563.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_SQUARE ), FALSE );
  564.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_SINE ), FALSE );
  565.     EnableWindow( GetDlgItem( hwndDlg, IDC_FRAME_WAVEFORM ), FALSE );
  566.  
  567.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_NEG_180 ), FALSE );
  568.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_NEG_90 ), FALSE );
  569.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_ZERO ), FALSE );
  570.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_90 ), FALSE );
  571.     EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_180 ), FALSE );
  572.     EnableWindow( GetDlgItem( hwndDlg, IDC_FRAME_PHASE ), FALSE );
  573. }
  574.  
  575.  
  576.  
  577.  
  578. //-----------------------------------------------------------------------------
  579. // Name: EnableSingleParameter
  580. // Desc: 
  581. //-----------------------------------------------------------------------------
  582. VOID EnableSingleParameter( HWND hwndDlg, DWORD resID )
  583. {
  584.     for ( DWORD i = resID; i < resID + 5; i++ )
  585.         EnableWindow( GetDlgItem( hwndDlg, i ), TRUE );      
  586. }
  587.  
  588.  
  589.  
  590.  
  591. //-----------------------------------------------------------------------------
  592. // Name: PosSlider
  593. // Desc: 
  594. //-----------------------------------------------------------------------------
  595. VOID PosSlider( HWND hwndDlg, DWORD dwSlider, FLOAT val, FLOAT min, FLOAT max, 
  596.                 FLOAT fSliderInc )
  597. {
  598.     HWND hwndSlider = GetDlgItem( hwndDlg, dwSlider );
  599.  
  600.     LONG lSliderInc = (LONG) ( (fSliderInc / (max - min)) * DEFAULT_SLIDER_MAX );
  601.     PostMessage( hwndSlider, TBM_SETLINESIZE, FALSE, lSliderInc );
  602.  
  603.     FLOAT res = ( val - min ) / ( max - min );
  604.     if( res < 0.0f )
  605.         res = 0.0f;
  606.     else if( res > 1.0f )
  607.         res = 1.0f;
  608.  
  609.     LONG pos = (LONG) ( res * DEFAULT_SLIDER_MAX );
  610.     PostMessage( hwndSlider, TBM_SETPOS, TRUE, pos );
  611. }
  612.  
  613.  
  614.  
  615.  
  616. //-----------------------------------------------------------------------------
  617. // Name: LoadSingleParameter
  618. // Desc: 
  619. //-----------------------------------------------------------------------------
  620. VOID LoadSingleParameter( HWND hwndDlg, DWORD id, const TCHAR * strName, FLOAT val, 
  621.                           FLOAT min, FLOAT max, FLOAT fSliderInc = 0.1f,
  622.                           DWORD dwPrecision = 1 )
  623. {
  624.     TCHAR strTemp[MAX_PATH];
  625.  
  626.     // wet dry mix
  627.     EnableSingleParameter( hwndDlg, id );
  628.     SendMessage( GetDlgItem( hwndDlg, id ), WM_SETTEXT, 0, ( LPARAM ) strName );
  629.  
  630.     switch( dwPrecision )
  631.     {
  632.         case 0:
  633.             sprintf( strTemp, "%.0f", val );
  634.             SendMessage( GetDlgItem( hwndDlg, id + 1 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  635.             sprintf( strTemp, "%.0f", min );
  636.             SendMessage( GetDlgItem( hwndDlg, id + 3 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  637.             sprintf( strTemp, "%.0f", max );
  638.             SendMessage( GetDlgItem( hwndDlg, id + 4 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  639.             break;
  640.         case 1:
  641.             sprintf( strTemp, "%.1f", val );
  642.             SendMessage( GetDlgItem( hwndDlg, id + 1 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  643.             sprintf( strTemp, "%.1f", min );
  644.             SendMessage( GetDlgItem( hwndDlg, id + 3 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  645.             sprintf( strTemp, "%.1f", max );
  646.             SendMessage( GetDlgItem( hwndDlg, id + 4 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  647.             break;
  648.         default:
  649.         case 2:
  650.             sprintf( strTemp, "%.2f", val );
  651.             SendMessage( GetDlgItem( hwndDlg, id + 1 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  652.             sprintf( strTemp, "%.2f", min );
  653.             SendMessage( GetDlgItem( hwndDlg, id + 3 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  654.             sprintf( strTemp, "%.2f", max );
  655.             SendMessage( GetDlgItem( hwndDlg, id + 4 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  656.             break;
  657.     }
  658.  
  659.     PosSlider( hwndDlg, id + 2, val, min, max, fSliderInc );
  660. }
  661.  
  662.  
  663.  
  664.  
  665. //-----------------------------------------------------------------------------
  666. // Name: SaveSingleParameter
  667. // Desc: 
  668. //-----------------------------------------------------------------------------
  669. VOID SaveSingleParameter( HWND hwndDlg, DWORD id, FLOAT * fVal, FLOAT fMin, FLOAT fMax, DWORD dwPrecision = 1 )
  670. {
  671.     TCHAR strTemp[MAX_PATH];
  672.  
  673.     DWORD dwPos = ( DWORD ) SendMessage( GetDlgItem( hwndDlg, id + 2), TBM_GETPOS, 0, 0 );
  674.  
  675.     FLOAT fPercent = (FLOAT) ( dwPos - DEFAULT_SLIDER_MIN ) / 
  676.                      (FLOAT) ( DEFAULT_SLIDER_MAX - DEFAULT_SLIDER_MIN );
  677.     *fVal = fPercent * ( fMax - fMin ) + fMin;
  678.  
  679.     switch( dwPrecision )
  680.     {
  681.         case 0:
  682.             sprintf( strTemp, "%.0f", *fVal );
  683.             break;
  684.         case 1:
  685.             sprintf( strTemp, "%.1f", *fVal );
  686.             break;
  687.         case 2:
  688.         default:
  689.             sprintf( strTemp, "%.2f", *fVal );
  690.             break;
  691.     }
  692.  
  693.     SendMessage( GetDlgItem( hwndDlg, id + 1 ), WM_SETTEXT, 0, ( LPARAM ) strTemp );
  694. }
  695.  
  696.  
  697.  
  698.  
  699. //-----------------------------------------------------------------------------
  700. // Name: LoadWaveformRadio
  701. // Desc: 
  702. //-----------------------------------------------------------------------------
  703. VOID LoadWaveformRadio( HWND hwndDlg, LONG waveform, LONG triangle, LONG square, LONG sine )
  704. {
  705.     if( waveform == triangle )
  706.         CheckRadioButton( hwndDlg, IDC_RADIO_TRIANGLE, IDC_RADIO_SINE, IDC_RADIO_TRIANGLE );
  707.     else if( waveform == square )
  708.         CheckRadioButton( hwndDlg, IDC_RADIO_TRIANGLE, IDC_RADIO_SINE, IDC_RADIO_SQUARE );
  709.     else if( waveform == sine )
  710.         CheckRadioButton( hwndDlg, IDC_RADIO_TRIANGLE, IDC_RADIO_SINE, IDC_RADIO_SINE );
  711.  
  712.     if( triangle >= 0 )
  713.         EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_TRIANGLE ), TRUE );
  714.     if( square >= 0 )
  715.         EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_SQUARE ), TRUE );
  716.     if( sine >= 0 )
  717.         EnableWindow( GetDlgItem( hwndDlg, IDC_RADIO_SINE ), TRUE );
  718.  
  719.     EnableWindow( GetDlgItem( hwndDlg, IDC_FRAME_WAVEFORM ), ( triangle + square + sine != -3 ) );
  720. }
  721.  
  722.  
  723.  
  724.  
  725. //-----------------------------------------------------------------------------
  726. // Name: LoadPhaseRadio
  727. // Desc: 
  728. //-----------------------------------------------------------------------------
  729. VOID LoadPhaseRadio( HWND hwndDlg, LONG phase, LONG neg180, LONG neg90, LONG zero, LONG pos90, LONG pos180 )
  730. {
  731.     for( int i = IDC_RADIO_NEG_180; i <= IDC_RADIO_180; i++ )
  732.         EnableWindow( GetDlgItem( hwndDlg, i ), TRUE );
  733.  
  734.     EnableWindow( GetDlgItem( hwndDlg, IDC_FRAME_PHASE), TRUE );
  735.  
  736.     if( phase == neg180 )
  737.         CheckRadioButton( hwndDlg, IDC_RADIO_NEG_180, IDC_RADIO_90, IDC_RADIO_NEG_180 );
  738.     else if( phase == neg90 )
  739.         CheckRadioButton( hwndDlg, IDC_RADIO_NEG_180, IDC_RADIO_90, IDC_RADIO_NEG_90 );
  740.     else if( phase == zero )
  741.         CheckRadioButton( hwndDlg, IDC_RADIO_NEG_180, IDC_RADIO_90, IDC_RADIO_ZERO );
  742.     else if( phase == pos90 )
  743.         CheckRadioButton( hwndDlg, IDC_RADIO_NEG_180, IDC_RADIO_90, IDC_RADIO_90 );
  744.     else if( phase == pos180 )
  745.         CheckRadioButton( hwndDlg, IDC_RADIO_NEG_180, IDC_RADIO_90, IDC_RADIO_180 );
  746. }
  747.  
  748.  
  749.  
  750.  
  751. //-----------------------------------------------------------------------------
  752. // Name: LoadParameterUI()
  753. // Desc: loads the paramter ui for particular effect
  754. //-----------------------------------------------------------------------------
  755. VOID LoadParameterUI( HWND hwndDlg, DWORD dwFXType )
  756. {
  757.     TCHAR strTemp[MAX_PATH];
  758.  
  759.     // reset the parameter ui
  760.     ResetParameterUI( hwndDlg );
  761.  
  762.     sprintf( strTemp, "Parameters for [ %s ]", g_strFXNames[dwFXType] );
  763.     SetDlgItemText( hwndDlg, IDC_FRAME, strTemp );
  764.  
  765.     switch( dwFXType)
  766.     {
  767.         case eSFX_chorus:
  768.         {            
  769.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Wet/Dry Mix (%)" ), g_lpFXManager->m_paramsChorus.fWetDryMix, DSFXCHORUS_WETDRYMIX_MIN, DSFXCHORUS_WETDRYMIX_MAX );
  770.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Depth (%)" ), g_lpFXManager->m_paramsChorus.fDepth, DSFXCHORUS_DEPTH_MIN, DSFXCHORUS_DEPTH_MAX );
  771.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "Feedback (%)" ), g_lpFXManager->m_paramsChorus.fFeedback, DSFXCHORUS_FEEDBACK_MIN, DSFXCHORUS_FEEDBACK_MAX );
  772.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME4, TEXT( "Frequency (Hz)" ), g_lpFXManager->m_paramsChorus.fFrequency, DSFXCHORUS_FREQUENCY_MIN, DSFXCHORUS_FREQUENCY_MAX );
  773.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME5, TEXT( "Delay (ms)" ), g_lpFXManager->m_paramsChorus.fDelay, DSFXCHORUS_DELAY_MIN, DSFXCHORUS_DELAY_MAX );
  774.             LoadWaveformRadio( hwndDlg, g_lpFXManager->m_paramsChorus.lWaveform, DSFXCHORUS_WAVE_TRIANGLE, -1, DSFXCHORUS_WAVE_SIN );
  775.             LoadPhaseRadio( hwndDlg, g_lpFXManager->m_paramsChorus.lPhase, DSFXCHORUS_PHASE_NEG_180, DSFXCHORUS_PHASE_NEG_90, DSFXCHORUS_PHASE_ZERO, DSFXCHORUS_PHASE_90, DSFXCHORUS_PHASE_180 );
  776.             break;
  777.         }
  778.  
  779.         case eSFX_compressor:
  780.         {            
  781.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Gain (dB)" ), g_lpFXManager->m_paramsCompressor.fGain, DSFXCOMPRESSOR_GAIN_MIN, DSFXCOMPRESSOR_GAIN_MAX );
  782.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Attack (ms)" ), g_lpFXManager->m_paramsCompressor.fAttack, DSFXCOMPRESSOR_ATTACK_MIN, DSFXCOMPRESSOR_ATTACK_MAX );
  783.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "Release (ms)" ), g_lpFXManager->m_paramsCompressor.fRelease, DSFXCOMPRESSOR_RELEASE_MIN, DSFXCOMPRESSOR_RELEASE_MAX );
  784.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME4, TEXT( "Threshold (dB)" ), g_lpFXManager->m_paramsCompressor.fThreshold, DSFXCOMPRESSOR_THRESHOLD_MIN, DSFXCOMPRESSOR_THRESHOLD_MAX );
  785.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME5, TEXT( "Ratio (x:1)" ), g_lpFXManager->m_paramsCompressor.fRatio, DSFXCOMPRESSOR_RATIO_MIN, DSFXCOMPRESSOR_RATIO_MAX );
  786.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME6, TEXT( "Predelay (ms)" ), g_lpFXManager->m_paramsCompressor.fPredelay, DSFXCOMPRESSOR_PREDELAY_MIN, DSFXCOMPRESSOR_PREDELAY_MAX, 0.05f, 2 );
  787.             break;
  788.         }
  789.  
  790.         case eSFX_distortion:
  791.         {            
  792.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Gain (dB)" ), g_lpFXManager->m_paramsDistortion.fGain, DSFXDISTORTION_GAIN_MIN, DSFXDISTORTION_GAIN_MAX );
  793.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Edge (%)" ), g_lpFXManager->m_paramsDistortion.fEdge, DSFXDISTORTION_EDGE_MIN, DSFXDISTORTION_EDGE_MAX );
  794.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "PostEQ Center Freq (Hz)" ), g_lpFXManager->m_paramsDistortion.fPostEQCenterFrequency, DSFXDISTORTION_POSTEQCENTERFREQUENCY_MIN, DSFXDISTORTION_POSTEQCENTERFREQUENCY_MAX, 1.0f, 0 );
  795.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME4, TEXT( "PostEQ Bandwidth (Hz)" ), g_lpFXManager->m_paramsDistortion.fPostEQBandwidth, DSFXDISTORTION_POSTEQBANDWIDTH_MIN, DSFXDISTORTION_POSTEQBANDWIDTH_MAX, 1.0f, 0 );
  796.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME5, TEXT( "PreLowpass Cutoff (Hz)" ), g_lpFXManager->m_paramsDistortion.fPreLowpassCutoff, DSFXDISTORTION_PRELOWPASSCUTOFF_MIN, DSFXDISTORTION_PRELOWPASSCUTOFF_MAX, 1.0f, 0 );
  797.             break;
  798.         }
  799.  
  800.         case eSFX_echo:
  801.         {            
  802.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Wet/Dry Mix (%)" ), g_lpFXManager->m_paramsEcho.fWetDryMix, DSFXECHO_WETDRYMIX_MIN, DSFXECHO_WETDRYMIX_MAX );
  803.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Feedback (%)" ), g_lpFXManager->m_paramsEcho.fFeedback, DSFXECHO_FEEDBACK_MIN, DSFXECHO_FEEDBACK_MAX );
  804.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "Left Delay (ms)" ), g_lpFXManager->m_paramsEcho.fLeftDelay, DSFXECHO_LEFTDELAY_MIN, DSFXECHO_LEFTDELAY_MAX );
  805.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME4, TEXT( "Right Delay (ms)" ), g_lpFXManager->m_paramsEcho.fRightDelay, DSFXECHO_RIGHTDELAY_MIN, DSFXECHO_RIGHTDELAY_MAX );
  806.             break;
  807.         }
  808.  
  809.         case eSFX_flanger:
  810.         {            
  811.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Wet/Dry Mix (%)" ), g_lpFXManager->m_paramsFlanger.fWetDryMix, DSFXFLANGER_WETDRYMIX_MIN, DSFXFLANGER_WETDRYMIX_MAX );
  812.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Depth (%)" ), g_lpFXManager->m_paramsFlanger.fDepth, DSFXFLANGER_DEPTH_MIN, DSFXFLANGER_DEPTH_MAX );
  813.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "Feedback (%)" ), g_lpFXManager->m_paramsFlanger.fFeedback, DSFXFLANGER_FEEDBACK_MIN, DSFXFLANGER_FEEDBACK_MAX );
  814.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME4, TEXT( "Frequency (Hz)" ), g_lpFXManager->m_paramsFlanger.fFrequency, DSFXFLANGER_FREQUENCY_MIN, DSFXFLANGER_FREQUENCY_MAX, 0.01f, 2 );
  815.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME5, TEXT( "Delay (ms)" ), g_lpFXManager->m_paramsFlanger.fDelay, DSFXFLANGER_DELAY_MIN, DSFXFLANGER_DELAY_MAX, 0.01f, 2 );
  816.             LoadWaveformRadio( hwndDlg, g_lpFXManager->m_paramsFlanger.lWaveform, DSFXFLANGER_WAVE_TRIANGLE, -1, DSFXFLANGER_WAVE_SIN );
  817.             LoadPhaseRadio( hwndDlg, g_lpFXManager->m_paramsFlanger.lPhase, DSFXFLANGER_PHASE_NEG_180, DSFXFLANGER_PHASE_NEG_90, DSFXFLANGER_PHASE_ZERO, DSFXFLANGER_PHASE_90, DSFXFLANGER_PHASE_180 );
  818.             break;
  819.         }
  820.  
  821.         case eSFX_gargle:
  822.         {            
  823.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Rate (Hz)" ), ( FLOAT ) g_lpFXManager->m_paramsGargle.dwRateHz, ( FLOAT ) DSFXGARGLE_RATEHZ_MIN, ( FLOAT ) DSFXGARGLE_RATEHZ_MAX );
  824.             LoadWaveformRadio( hwndDlg, g_lpFXManager->m_paramsGargle.dwWaveShape, DSFXGARGLE_WAVE_TRIANGLE, DSFXGARGLE_WAVE_SQUARE, -1 );
  825.             break;
  826.         }
  827.  
  828.         case eSFX_parameq:
  829.         {            
  830.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "Center Freq (Hz)" ), g_lpFXManager->m_paramsParamEq.fCenter, DSFXPARAMEQ_CENTER_MIN, DSFXPARAMEQ_CENTER_MAX );
  831.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Bandwidth (Hz)" ), g_lpFXManager->m_paramsParamEq.fBandwidth, DSFXPARAMEQ_BANDWIDTH_MIN, DSFXPARAMEQ_BANDWIDTH_MAX );
  832.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "Gain (dB)" ), g_lpFXManager->m_paramsParamEq.fGain, DSFXPARAMEQ_GAIN_MIN, DSFXPARAMEQ_GAIN_MAX );
  833.             break;
  834.         }
  835.  
  836.         case eSFX_reverb:
  837.         {            
  838.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME1, TEXT( "In Gain (dB)" ), g_lpFXManager->m_paramsReverb.fInGain, DSFX_WAVESREVERB_INGAIN_MIN, DSFX_WAVESREVERB_INGAIN_MAX );
  839.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME2, TEXT( "Reverb Mix (dB)" ), g_lpFXManager->m_paramsReverb.fReverbMix, DSFX_WAVESREVERB_REVERBMIX_MIN, DSFX_WAVESREVERB_REVERBMIX_MAX );
  840.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME3, TEXT( "Reverb Time (ms)" ), g_lpFXManager->m_paramsReverb.fReverbTime, DSFX_WAVESREVERB_REVERBTIME_MIN, DSFX_WAVESREVERB_REVERBTIME_MAX );
  841.             LoadSingleParameter( hwndDlg, IDC_PARAM_NAME4, TEXT( "HighFreq RT Ratio (x:1)" ), g_lpFXManager->m_paramsReverb.fHighFreqRTRatio, DSFX_WAVESREVERB_HIGHFREQRTRATIO_MIN, DSFX_WAVESREVERB_HIGHFREQRTRATIO_MAX, 0.01f, 2 );
  842.             break;
  843.         }
  844.     }
  845. }
  846.  
  847.  
  848.  
  849.  
  850. //-----------------------------------------------------------------------------
  851. // Name: OnEffectChanged()  
  852. // Desc: Called when the UI prompted an effect change
  853. //-----------------------------------------------------------------------------
  854. VOID OnEffectChanged( HWND hwndDlg )
  855. {
  856.     switch( g_dwCurrentFXType )
  857.     {
  858.         case eSFX_chorus:
  859.         {
  860.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsChorus.fWetDryMix, DSFXCHORUS_WETDRYMIX_MIN, DSFXCHORUS_WETDRYMIX_MAX );
  861.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsChorus.fDepth, DSFXCHORUS_DEPTH_MIN, DSFXCHORUS_DEPTH_MAX );
  862.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsChorus.fFeedback, DSFXCHORUS_FEEDBACK_MIN, DSFXCHORUS_FEEDBACK_MAX );
  863.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME4, &g_lpFXManager->m_paramsChorus.fFrequency, DSFXCHORUS_FREQUENCY_MIN, DSFXCHORUS_FREQUENCY_MAX );
  864.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME5, &g_lpFXManager->m_paramsChorus.fDelay, DSFXCHORUS_DELAY_MIN, DSFXCHORUS_DELAY_MAX );
  865.  
  866.             if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_TRIANGLE ) == BST_CHECKED )
  867.                 g_lpFXManager->m_paramsChorus.lWaveform = DSFXCHORUS_WAVE_TRIANGLE;
  868.             else
  869.                 g_lpFXManager->m_paramsChorus.lWaveform = DSFXCHORUS_WAVE_SIN;
  870.  
  871.             if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_NEG_180 ) == BST_CHECKED )
  872.                 g_lpFXManager->m_paramsChorus.lPhase = DSFXCHORUS_PHASE_NEG_180;
  873.             else if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_NEG_90 ) == BST_CHECKED )
  874.                 g_lpFXManager->m_paramsChorus.lPhase = DSFXCHORUS_PHASE_NEG_90;
  875.             else if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_ZERO ) == BST_CHECKED )
  876.                 g_lpFXManager->m_paramsChorus.lPhase = DSFXCHORUS_PHASE_ZERO;
  877.             else if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_90 ) == BST_CHECKED )
  878.                 g_lpFXManager->m_paramsChorus.lPhase = DSFXCHORUS_PHASE_90;
  879.             else
  880.                 g_lpFXManager->m_paramsChorus.lPhase = DSFXCHORUS_PHASE_180;
  881.  
  882.             if( g_lpFXManager->m_lpChorus )
  883.                 g_lpFXManager->m_lpChorus->SetAllParameters( &g_lpFXManager->m_paramsChorus );
  884.  
  885.             break;
  886.         }
  887.  
  888.         case eSFX_compressor:
  889.         {
  890.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsCompressor.fGain, DSFXCOMPRESSOR_GAIN_MIN, DSFXCOMPRESSOR_GAIN_MAX );
  891.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsCompressor.fAttack, DSFXCOMPRESSOR_ATTACK_MIN, DSFXCOMPRESSOR_ATTACK_MAX );
  892.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsCompressor.fRelease, DSFXCOMPRESSOR_RELEASE_MIN, DSFXCOMPRESSOR_RELEASE_MAX );
  893.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME4, &g_lpFXManager->m_paramsCompressor.fThreshold, DSFXCOMPRESSOR_THRESHOLD_MIN, DSFXCOMPRESSOR_THRESHOLD_MAX );
  894.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME5, &g_lpFXManager->m_paramsCompressor.fRatio, DSFXCOMPRESSOR_RATIO_MIN, DSFXCOMPRESSOR_RATIO_MAX );
  895.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME6, &g_lpFXManager->m_paramsCompressor.fPredelay, DSFXCOMPRESSOR_PREDELAY_MIN, DSFXCOMPRESSOR_PREDELAY_MAX, 2 );
  896.  
  897.             if( g_lpFXManager->m_lpCompressor )
  898.                 g_lpFXManager->m_lpCompressor->SetAllParameters( &g_lpFXManager->m_paramsCompressor );
  899.             break;
  900.         }
  901.  
  902.         case eSFX_distortion:
  903.         {
  904.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsDistortion.fGain, DSFXDISTORTION_GAIN_MIN, DSFXDISTORTION_GAIN_MAX );
  905.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsDistortion.fEdge, DSFXDISTORTION_EDGE_MIN, DSFXDISTORTION_EDGE_MAX );
  906.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsDistortion.fPostEQCenterFrequency, DSFXDISTORTION_POSTEQCENTERFREQUENCY_MIN, DSFXDISTORTION_POSTEQCENTERFREQUENCY_MAX, 0 );
  907.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME4, &g_lpFXManager->m_paramsDistortion.fPostEQBandwidth, DSFXDISTORTION_POSTEQBANDWIDTH_MIN, DSFXDISTORTION_POSTEQBANDWIDTH_MAX, 0 );
  908.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME5, &g_lpFXManager->m_paramsDistortion.fPreLowpassCutoff, DSFXDISTORTION_PRELOWPASSCUTOFF_MIN, DSFXDISTORTION_PRELOWPASSCUTOFF_MAX, 0 );
  909.  
  910.             if( g_lpFXManager->m_lpDistortion )
  911.                 g_lpFXManager->m_lpDistortion->SetAllParameters( &g_lpFXManager->m_paramsDistortion );
  912.             break;
  913.         }
  914.  
  915.         case eSFX_echo:
  916.         {
  917.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsEcho.fWetDryMix, DSFXECHO_WETDRYMIX_MIN, DSFXECHO_WETDRYMIX_MAX );
  918.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsEcho.fFeedback, DSFXECHO_FEEDBACK_MIN, DSFXECHO_FEEDBACK_MAX );
  919.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsEcho.fLeftDelay, DSFXECHO_LEFTDELAY_MIN, DSFXECHO_LEFTDELAY_MAX );
  920.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME4, &g_lpFXManager->m_paramsEcho.fRightDelay, DSFXECHO_RIGHTDELAY_MIN, DSFXECHO_RIGHTDELAY_MAX );
  921.  
  922.             if( g_lpFXManager->m_lpEcho )
  923.                 g_lpFXManager->m_lpEcho->SetAllParameters( &g_lpFXManager->m_paramsEcho );
  924.             break;
  925.         }
  926.  
  927.         case eSFX_flanger:
  928.         {
  929.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsFlanger.fWetDryMix, DSFXFLANGER_WETDRYMIX_MIN, DSFXFLANGER_WETDRYMIX_MAX );
  930.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsFlanger.fDepth, DSFXFLANGER_DEPTH_MIN, DSFXFLANGER_DEPTH_MAX );
  931.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsFlanger.fFeedback, DSFXFLANGER_FEEDBACK_MIN, DSFXFLANGER_FEEDBACK_MAX );
  932.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME4, &g_lpFXManager->m_paramsFlanger.fFrequency, DSFXFLANGER_FREQUENCY_MIN, DSFXFLANGER_FREQUENCY_MAX, 2 );
  933.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME5, &g_lpFXManager->m_paramsFlanger.fDelay, DSFXFLANGER_DELAY_MIN, DSFXFLANGER_DELAY_MAX, 2 );
  934.  
  935.             if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_TRIANGLE ) == BST_CHECKED )
  936.                 g_lpFXManager->m_paramsFlanger.lWaveform = DSFXFLANGER_WAVE_TRIANGLE;
  937.             else
  938.                 g_lpFXManager->m_paramsFlanger.lWaveform = DSFXFLANGER_WAVE_SIN;
  939.  
  940.             if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_NEG_180 ) == BST_CHECKED )
  941.                 g_lpFXManager->m_paramsFlanger.lPhase = DSFXFLANGER_PHASE_NEG_180;
  942.             else if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_NEG_90 ) == BST_CHECKED )
  943.                 g_lpFXManager->m_paramsFlanger.lPhase = DSFXFLANGER_PHASE_NEG_90;
  944.             else if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_ZERO ) == BST_CHECKED )
  945.                 g_lpFXManager->m_paramsFlanger.lPhase = DSFXFLANGER_PHASE_ZERO;
  946.             else if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_90 ) == BST_CHECKED )
  947.                 g_lpFXManager->m_paramsFlanger.lPhase = DSFXFLANGER_PHASE_90;
  948.             else
  949.                 g_lpFXManager->m_paramsFlanger.lPhase = DSFXFLANGER_PHASE_180;
  950.  
  951.             if( g_lpFXManager->m_lpFlanger )
  952.                 g_lpFXManager->m_lpFlanger->SetAllParameters( &g_lpFXManager->m_paramsFlanger );
  953.             break;
  954.         }
  955.  
  956.         case eSFX_gargle:
  957.         {
  958.             FLOAT fRateHz;
  959.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &fRateHz, DSFXGARGLE_RATEHZ_MIN, DSFXGARGLE_RATEHZ_MAX );
  960.             g_lpFXManager->m_paramsGargle.dwRateHz = (DWORD) fRateHz;
  961.  
  962.             if( IsDlgButtonChecked( hwndDlg, IDC_RADIO_TRIANGLE ) == BST_CHECKED )
  963.                 g_lpFXManager->m_paramsGargle.dwWaveShape = DSFXGARGLE_WAVE_TRIANGLE;
  964.             else
  965.                 g_lpFXManager->m_paramsGargle.dwWaveShape = DSFXGARGLE_WAVE_SQUARE;
  966.  
  967.             if( g_lpFXManager->m_lpGargle )
  968.                 g_lpFXManager->m_lpGargle->SetAllParameters( &g_lpFXManager->m_paramsGargle );
  969.             break;
  970.         }
  971.  
  972.         case eSFX_parameq:
  973.         {
  974.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsParamEq.fCenter, DSFXPARAMEQ_CENTER_MIN, DSFXPARAMEQ_CENTER_MAX );
  975.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsParamEq.fBandwidth, DSFXPARAMEQ_BANDWIDTH_MIN, DSFXPARAMEQ_BANDWIDTH_MAX );
  976.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsParamEq.fGain, DSFXPARAMEQ_GAIN_MIN, DSFXPARAMEQ_GAIN_MAX );
  977.  
  978.             if( g_lpFXManager->m_lpParamEq )
  979.                 g_lpFXManager->m_lpParamEq->SetAllParameters( &g_lpFXManager->m_paramsParamEq );
  980.             break;
  981.         }
  982.  
  983.         case eSFX_reverb:
  984.         {
  985.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME1, &g_lpFXManager->m_paramsReverb.fInGain, DSFX_WAVESREVERB_INGAIN_MIN, DSFX_WAVESREVERB_INGAIN_MAX );
  986.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME2, &g_lpFXManager->m_paramsReverb.fReverbMix, DSFX_WAVESREVERB_REVERBMIX_MIN, DSFX_WAVESREVERB_REVERBMIX_MAX );
  987.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME3, &g_lpFXManager->m_paramsReverb.fReverbTime, DSFX_WAVESREVERB_REVERBTIME_MIN, DSFX_WAVESREVERB_REVERBTIME_MAX );
  988.             SaveSingleParameter( hwndDlg, IDC_PARAM_NAME4, &g_lpFXManager->m_paramsReverb.fHighFreqRTRatio, DSFX_WAVESREVERB_HIGHFREQRTRATIO_MIN, DSFX_WAVESREVERB_HIGHFREQRTRATIO_MAX, 2 );
  989.  
  990.             if( g_lpFXManager->m_lpReverb )
  991.                 g_lpFXManager->m_lpReverb->SetAllParameters( &g_lpFXManager->m_paramsReverb );
  992.             break;
  993.         }
  994.     }
  995. }
  996.  
  997.  
  998.  
  999.  
  1000. //-----------------------------------------------------------------------------
  1001. // Name: ValidateFile()
  1002. // Desc: Checks to see if the file exists
  1003. //-----------------------------------------------------------------------------
  1004. HRESULT ValidateFile( HWND hDlg, TCHAR* strFileName )
  1005. {
  1006.     if( -1 == GetFileAttributes(strFileName) )
  1007.         return E_FAIL;
  1008.         
  1009.     SetDlgItemText( hDlg, IDC_TEXT_FILENAME, strFileName );
  1010.     SetDlgItemText( hDlg, IDC_TEXT_STATUS, TEXT("File loaded.") );
  1011.     strcpy( g_strFileName, strFileName );
  1012.     
  1013.     return S_OK;        
  1014. }
  1015.  
  1016.  
  1017.  
  1018.  
  1019. //-----------------------------------------------------------------------------
  1020. // Name: CSoundFXManager()
  1021. // Desc: constructor
  1022. //-----------------------------------------------------------------------------
  1023. CSoundFXManager::CSoundFXManager()
  1024. {
  1025.     m_lpChorus = NULL;
  1026.     m_lpCompressor = NULL;
  1027.     m_lpDistortion = NULL;
  1028.     m_lpEcho = NULL;
  1029.     m_lpFlanger = NULL;
  1030.     m_lpGargle = NULL;
  1031.     m_lpParamEq = NULL;
  1032.     m_lpReverb = NULL;
  1033.  
  1034.     ZeroMemory( &m_paramsChorus, sizeof( DSFXChorus ) );
  1035.     ZeroMemory( &m_paramsCompressor, sizeof( DSFXCompressor ) );
  1036.     ZeroMemory( &m_paramsDistortion, sizeof( DSFXDistortion ) );
  1037.     ZeroMemory( &m_paramsFlanger, sizeof( DSFXFlanger ) );
  1038.     ZeroMemory( &m_paramsEcho, sizeof( DSFXEcho ) );
  1039.     ZeroMemory( &m_paramsGargle, sizeof( DSFXGargle ) );
  1040.     ZeroMemory( &m_paramsParamEq, sizeof( DSFXParamEq ) );
  1041.     ZeroMemory( &m_paramsReverb, sizeof( DSFXWavesReverb ) );
  1042.  
  1043.     m_dwNumFX = 0;
  1044.     ZeroMemory( m_rgFxDesc, sizeof( DSEFFECTDESC ) * eNUM_SFX );
  1045.     ZeroMemory( m_rgRefGuids, sizeof( GUID * ) * eNUM_SFX );
  1046.     ZeroMemory( m_rgPtrs, sizeof(LPVOID*) * eNUM_SFX );
  1047.     ZeroMemory( m_rgLoaded, sizeof( BOOL ) * eNUM_SFX );
  1048.  
  1049.     m_lpDSB8 = NULL;
  1050.     m_pAudioPath = NULL;
  1051. }
  1052.  
  1053.  
  1054.  
  1055.  
  1056. //-----------------------------------------------------------------------------
  1057. // Name: ~CSoundFXManager()
  1058. // Desc: destructor
  1059. //-----------------------------------------------------------------------------
  1060. CSoundFXManager::~CSoundFXManager()
  1061. {
  1062.     // free any effects
  1063.     DisableAllFX();
  1064.     SAFE_RELEASE( m_lpDSB8 );
  1065.     SAFE_RELEASE( m_pAudioPath );
  1066. }
  1067.  
  1068.  
  1069.  
  1070.  
  1071. //-----------------------------------------------------------------------------
  1072. // Name: Initialize()
  1073. // Desc: associates a DirectSoundBuffer with the manager, any effects
  1074. //       enabled in the old DirectSoundBuffer will be disabled, 
  1075. //       and the effect objects released
  1076. //-----------------------------------------------------------------------------
  1077. HRESULT CSoundFXManager::Initialize( IDirectMusicAudioPath8* pAudioPath, 
  1078.                                      BOOL bLoadDefaultParamValues )
  1079. {
  1080.     HRESULT hr;
  1081.  
  1082.     if( m_lpDSB8 )
  1083.     {
  1084.         // release the effect for the previously associated sound buffers
  1085.         DisableAllFX();
  1086.         SAFE_RELEASE( m_lpDSB8 );
  1087.         SAFE_RELEASE( m_pAudioPath );
  1088.     }
  1089.  
  1090.     if( NULL == pAudioPath )
  1091.         return S_OK;
  1092.     
  1093.     if( FAILED( hr = pAudioPath->GetObjectInPath( DMUS_PCHANNEL_ALL,
  1094.                 DMUS_PATH_BUFFER, 0, GUID_NULL, 0, IID_IDirectSoundBuffer8, 
  1095.                 (LPVOID*) &m_lpDSB8 )))
  1096.         return hr;
  1097.  
  1098.     m_pAudioPath = pAudioPath;
  1099.  
  1100.     if( bLoadDefaultParamValues )
  1101.         LoadDefaultParamValues();
  1102.  
  1103.     return S_OK;
  1104. }
  1105.  
  1106.  
  1107.  
  1108.  
  1109. //-----------------------------------------------------------------------------
  1110. // Name: UnInitialize()
  1111. // Desc: the manager goes back to default state, the effects params, however
  1112. //       will not be reset
  1113. //-----------------------------------------------------------------------------
  1114. HRESULT CSoundFXManager::UnInitialize()
  1115. {
  1116.     Initialize( NULL, FALSE );
  1117.  
  1118.     return S_OK;
  1119. }
  1120.  
  1121.  
  1122.  
  1123.  
  1124. //-----------------------------------------------------------------------------
  1125. // Name: LoadDefaultParamValues()
  1126. // Desc: loads the default param value for each effect
  1127. //-----------------------------------------------------------------------------
  1128. HRESULT CSoundFXManager::LoadDefaultParamValues()
  1129. {
  1130.     DWORD i;
  1131.  
  1132.     if( NULL == m_lpDSB8 )
  1133.         return E_FAIL;
  1134.  
  1135.     for( i = eSFX_chorus; i < eNUM_SFX; i++ )
  1136.         SetFXEnable( i );
  1137.     
  1138.     ActivateFX();
  1139.  
  1140.     if( m_lpChorus )
  1141.         m_lpChorus->GetAllParameters( &m_paramsChorus );
  1142.  
  1143.     if( m_lpCompressor )
  1144.         m_lpCompressor->GetAllParameters( &m_paramsCompressor );
  1145.     
  1146.     if( m_lpDistortion )
  1147.         m_lpDistortion->GetAllParameters( &m_paramsDistortion );
  1148.  
  1149.     if( m_lpEcho )
  1150.         m_lpEcho->GetAllParameters( &m_paramsEcho );
  1151.  
  1152.     if( m_lpFlanger )
  1153.         m_lpFlanger->GetAllParameters( &m_paramsFlanger );
  1154.  
  1155.     if( m_lpGargle )
  1156.         m_lpGargle->GetAllParameters( &m_paramsGargle );
  1157.  
  1158.     if( m_lpParamEq )
  1159.         m_lpParamEq->GetAllParameters( &m_paramsParamEq );
  1160.  
  1161.     if( m_lpReverb )
  1162.         m_lpReverb->GetAllParameters( &m_paramsReverb );
  1163.  
  1164.     DisableAllFX();
  1165.  
  1166.     return S_OK;
  1167. }
  1168.  
  1169.  
  1170.  
  1171.  
  1172. //-----------------------------------------------------------------------------
  1173. // Name: LoadCurrentFXParameters
  1174. // Desc: loads the default param value for each effect
  1175. //-----------------------------------------------------------------------------
  1176. HRESULT CSoundFXManager::LoadCurrentFXParameters()
  1177. {
  1178.     if( m_lpChorus )
  1179.         m_lpChorus->SetAllParameters( &m_paramsChorus );
  1180.  
  1181.     if( m_lpCompressor )
  1182.         m_lpCompressor->SetAllParameters( &m_paramsCompressor );
  1183.     
  1184.     if( m_lpDistortion )
  1185.         m_lpDistortion->SetAllParameters( &m_paramsDistortion );
  1186.  
  1187.     if( m_lpEcho )
  1188.         m_lpEcho->SetAllParameters( &m_paramsEcho );
  1189.  
  1190.     if( m_lpFlanger )
  1191.         m_lpFlanger->SetAllParameters( &m_paramsFlanger );
  1192.  
  1193.     if( m_lpGargle )
  1194.         m_lpGargle->SetAllParameters( &m_paramsGargle );
  1195.  
  1196.     if( m_lpParamEq )
  1197.         m_lpParamEq->SetAllParameters( &m_paramsParamEq );
  1198.  
  1199.     if( m_lpReverb )
  1200.         m_lpReverb->SetAllParameters( &m_paramsReverb );
  1201.  
  1202.     return S_OK;
  1203. }
  1204.  
  1205.  
  1206.  
  1207.  
  1208. //-----------------------------------------------------------------------------
  1209. // Name: SetFXEnable()
  1210. // Desc: enables a sound effect for the sound buffer associated with this
  1211. //-----------------------------------------------------------------------------
  1212. HRESULT CSoundFXManager::SetFXEnable( DWORD esfxType )
  1213. {
  1214.     HRESULT hr;
  1215.  
  1216.     if( esfxType >= eNUM_SFX )
  1217.         return E_FAIL;
  1218.  
  1219.     if( m_rgLoaded[esfxType] )
  1220.         return S_FALSE;
  1221.     else
  1222.         m_rgLoaded[esfxType] = TRUE;
  1223.  
  1224.     switch ( esfxType )
  1225.     {
  1226.     case eSFX_chorus:
  1227.         hr = EnableGenericFX( GUID_DSFX_STANDARD_CHORUS,     IID_IDirectSoundFXChorus8,      
  1228.                               (LPVOID*) &m_lpChorus );
  1229.         break;
  1230.     case eSFX_compressor:
  1231.         hr = EnableGenericFX( GUID_DSFX_STANDARD_COMPRESSOR, IID_IDirectSoundFXCompressor8,  
  1232.                               (LPVOID*) &m_lpCompressor );
  1233.         break;
  1234.     case eSFX_distortion:
  1235.         hr = EnableGenericFX( GUID_DSFX_STANDARD_DISTORTION, IID_IDirectSoundFXDistortion8,  
  1236.                               (LPVOID*) &m_lpDistortion );
  1237.         break;
  1238.     case eSFX_echo:
  1239.         hr = EnableGenericFX( GUID_DSFX_STANDARD_ECHO,       IID_IDirectSoundFXEcho8,        
  1240.                               (LPVOID*) &m_lpEcho );
  1241.         break;
  1242.     case eSFX_flanger:
  1243.         hr = EnableGenericFX( GUID_DSFX_STANDARD_FLANGER,    IID_IDirectSoundFXFlanger8,     
  1244.                               (LPVOID*) &m_lpFlanger );
  1245.         break;
  1246.     case eSFX_gargle:
  1247.         hr = EnableGenericFX( GUID_DSFX_STANDARD_GARGLE,     IID_IDirectSoundFXGargle8,      
  1248.                               (LPVOID*) &m_lpGargle );
  1249.         break;
  1250.     case eSFX_parameq:
  1251.         hr = EnableGenericFX( GUID_DSFX_STANDARD_PARAMEQ,    IID_IDirectSoundFXParamEq8,     
  1252.                               (LPVOID*) &m_lpParamEq );
  1253.         break;
  1254.     case eSFX_reverb:
  1255.         hr = EnableGenericFX( GUID_DSFX_WAVES_REVERB,        IID_IDirectSoundFXWavesReverb8, 
  1256.                               (LPVOID*) &m_lpReverb );
  1257.         break;
  1258.     default:
  1259.         hr = E_FAIL;
  1260.         break;
  1261.     }
  1262.  
  1263.     return hr;
  1264. }
  1265.  
  1266.  
  1267.  
  1268.  
  1269. //-----------------------------------------------------------------------------
  1270. // Name: DisableAllFX()
  1271. // Desc: disables all effect in the DirectSoundBuffer, and releases all effect
  1272. //       object.
  1273. //-----------------------------------------------------------------------------
  1274. HRESULT CSoundFXManager::DisableAllFX()
  1275. {
  1276.     HRESULT hr;
  1277.  
  1278.     // release all effect interfaces created with this manager so far
  1279.     SAFE_RELEASE( m_lpChorus );
  1280.     SAFE_RELEASE( m_lpCompressor );
  1281.     SAFE_RELEASE( m_lpDistortion );
  1282.     SAFE_RELEASE( m_lpEcho );
  1283.     SAFE_RELEASE( m_lpFlanger );
  1284.     SAFE_RELEASE( m_lpGargle );
  1285.     SAFE_RELEASE( m_lpParamEq );
  1286.     SAFE_RELEASE( m_lpReverb );
  1287.     
  1288.     m_dwNumFX = 0;
  1289.     ZeroMemory( m_rgFxDesc, sizeof( DSEFFECTDESC ) * eNUM_SFX );
  1290.     ZeroMemory( m_rgRefGuids, sizeof( GUID * ) * eNUM_SFX );
  1291.     ZeroMemory( m_rgPtrs, sizeof(LPVOID*) * eNUM_SFX );
  1292.     ZeroMemory( m_rgLoaded, sizeof( BOOL ) * eNUM_SFX );
  1293.  
  1294.     if( NULL == m_lpDSB8 )
  1295.         return E_FAIL;
  1296.  
  1297.     if( m_pAudioPath )
  1298.         m_pAudioPath->Activate( FALSE );
  1299.     
  1300.     // this removes all fx from the buffer
  1301.     if( FAILED( hr = m_lpDSB8->SetFX( 0, NULL, NULL ) ) )
  1302.         return DXTRACE_ERR( TEXT("SetFX"), hr );
  1303.  
  1304.     if( m_pAudioPath )
  1305.         m_pAudioPath->Activate( TRUE );
  1306.     
  1307.     return S_OK;
  1308. }
  1309.  
  1310.  
  1311.  
  1312.  
  1313. //-----------------------------------------------------------------------------
  1314. // Name: ActivateFX()
  1315. // Desc: activate the effects enabled from EnableFX()
  1316. //-----------------------------------------------------------------------------
  1317. HRESULT CSoundFXManager::ActivateFX()
  1318. {
  1319.     DWORD dwResults[eNUM_SFX];
  1320.     HRESULT hr;
  1321.     DWORD i;
  1322.  
  1323.     if( NULL == m_lpDSB8 )
  1324.         return E_FAIL;
  1325.  
  1326.     if( m_dwNumFX == 0 )
  1327.         return S_FALSE;
  1328.  
  1329.     if( m_pAudioPath )
  1330.         m_pAudioPath->Activate( FALSE );
  1331.  
  1332.     if( FAILED( hr = m_lpDSB8->SetFX( m_dwNumFX, m_rgFxDesc, dwResults ) ) )
  1333.         return DXTRACE_ERR( TEXT("SetFX"), hr );
  1334.  
  1335.     // get reference to the effect object
  1336.     for( i = 0; i < m_dwNumFX; i++ )
  1337.         if( FAILED( hr = m_lpDSB8->GetObjectInPath( m_rgFxDesc[i].guidDSFXClass, 0, *m_rgRefGuids[i], m_rgPtrs[i] ) ) )
  1338.             return hr;
  1339.  
  1340.     if( m_pAudioPath )
  1341.         m_pAudioPath->Activate( TRUE );
  1342.  
  1343.     return S_OK;
  1344. }
  1345.  
  1346.  
  1347.  
  1348.  
  1349. //-----------------------------------------------------------------------------
  1350. // Name: EnableGenericFX()
  1351. // Desc: given information, tries to enabled an effect in a DirectSoundBuffer8,
  1352. //       and tries obtain reference to effect interface
  1353. //-----------------------------------------------------------------------------
  1354. HRESULT CSoundFXManager::EnableGenericFX( GUID guidSFXClass, REFGUID rguidInterface, LPVOID * ppObj )
  1355. {
  1356.     // if an effect already allocated
  1357.     if( *ppObj )
  1358.         return S_FALSE;
  1359.  
  1360.     if( m_dwNumFX >= eNUM_SFX )
  1361.         return E_FAIL;
  1362.  
  1363.     // set the effect to be enabled
  1364.     ZeroMemory( &m_rgFxDesc[m_dwNumFX], sizeof(DSEFFECTDESC) );
  1365.     m_rgFxDesc[m_dwNumFX].dwSize         = sizeof(DSEFFECTDESC);
  1366.     m_rgFxDesc[m_dwNumFX].dwFlags        = 0;
  1367.     CopyMemory( &m_rgFxDesc[m_dwNumFX].guidDSFXClass, &guidSFXClass, sizeof(GUID) );
  1368.  
  1369.     m_rgRefGuids[m_dwNumFX] = &rguidInterface;
  1370.     m_rgPtrs[m_dwNumFX] = ppObj;
  1371.  
  1372.     m_dwNumFX++;
  1373.  
  1374.     return S_OK;
  1375. }
  1376.  
  1377.  
  1378.  
  1379.  
  1380. //-----------------------------------------------------------------------------
  1381. // Name: ProcessDirectMusicMessages()
  1382. // Desc: 
  1383. //-----------------------------------------------------------------------------
  1384. HRESULT ProcessDirectMusicMessages( HWND hDlg )
  1385. {
  1386.     HRESULT hr;
  1387.     IDirectMusicPerformance8* pPerf = NULL;
  1388.     DMUS_NOTIFICATION_PMSG* pPMsg;
  1389.         
  1390.     if( NULL == g_lpMusicManager )
  1391.         return S_OK;
  1392.  
  1393.     pPerf = g_lpMusicManager->GetPerformance();
  1394.  
  1395.     // Get waiting notification message from the performance
  1396.     while( S_OK == pPerf->GetNotificationPMsg( &pPMsg ) )
  1397.     {
  1398.         switch( pPMsg->dwNotificationOption )
  1399.         {
  1400.         case DMUS_NOTIFICATION_SEGEND:
  1401.             if( pPMsg->punkUser )
  1402.             {
  1403.                 IDirectMusicSegmentState8* pSegmentState   = NULL;
  1404.                 IDirectMusicSegment*       pNotifySegment   = NULL;
  1405.                 IDirectMusicSegment8*      pNotifySegment8  = NULL;
  1406.                 IDirectMusicSegment8*      pPrimarySegment8 = NULL;
  1407.  
  1408.                 // The pPMsg->punkUser contains a IDirectMusicSegmentState8, 
  1409.                 // which we can query for the segment that the SegmentState refers to.
  1410.                 if( FAILED( hr = pPMsg->punkUser->QueryInterface( IID_IDirectMusicSegmentState8,
  1411.                                                                   (VOID**) &pSegmentState ) ) )
  1412.                     return DXTRACE_ERR( TEXT("QueryInterface"), hr );
  1413.  
  1414.                 if( FAILED( hr = pSegmentState->GetSegment( &pNotifySegment ) ) )
  1415.                 {
  1416.                     // Sometimes the segend arrives after the segment is gone
  1417.                     // This can happen when you load another segment as 
  1418.                     // a motif or the segment is ending
  1419.                     if( hr == DMUS_E_NOT_FOUND )
  1420.                     {
  1421.                         SAFE_RELEASE( pSegmentState );
  1422.                         return S_OK;
  1423.                     }
  1424.  
  1425.                     return DXTRACE_ERR( TEXT("GetSegment"), hr );
  1426.                 }
  1427.  
  1428.                 if( FAILED( hr = pNotifySegment->QueryInterface( IID_IDirectMusicSegment8,
  1429.                                                                  (VOID**) &pNotifySegment8 ) ) )
  1430.                     return DXTRACE_ERR( TEXT("QueryInterface"), hr );
  1431.  
  1432.                 // Get the IDirectMusicSegment for the primary segment
  1433.                 pPrimarySegment8 = g_pSegment->GetSegment();
  1434.  
  1435.                 // Figure out which segment this is
  1436.                 if( pNotifySegment8 == pPrimarySegment8 )
  1437.                 {
  1438.                     // Update the UI controls to show the sound as stopped
  1439.                     EnablePlayUI( hDlg, TRUE );
  1440.                 }
  1441.  
  1442.                 // Cleanup
  1443.                 SAFE_RELEASE( pSegmentState );
  1444.                 SAFE_RELEASE( pNotifySegment );
  1445.                 SAFE_RELEASE( pNotifySegment8 );
  1446.             }
  1447.             break;
  1448.         }
  1449.  
  1450.         pPerf->FreePMsg( (DMUS_PMSG*)pPMsg ); 
  1451.     }
  1452.  
  1453.     return S_OK;
  1454. }
  1455.